package com.simple.business.config.properties;

import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @desc
 * @Author Simple
 * @Date 2025/3/14 22:00
 **/
@org.springframework.context.annotation.Configuration
@Data
@AllArgsConstructor
@NoArgsConstructor
@ConfigurationProperties("system-config.qiniu-oss")
public class QiNiuYunConfig {

    private String uriPrefix;
    private String fileNameFix;
    private String accessKeyId;
    private String accessKeySecret;
    private String bucketName;

    private Configuration qnConfig() {
        return new Configuration(Region.huadong());//根据自己机房的位置来选择
    }

    @Bean
    public Auth getAuth(){
        return Auth.create(accessKeyId,accessKeySecret);
    }

    @Bean
    public UploadManager getUploadManager(){
        return new UploadManager(new Configuration());
    }

    @Bean
    public BucketManager getBucketManager(){
        return new BucketManager(getAuth(),qnConfig());
    }

}
